{$CLEO .qa}
{$USE CLEO+}
{$USE ini}

0000: NOP

script_name "ChefQa"

// By ArtemQa146

const
    Chef_1 = 31@
    obj_1 = 30@
    Ped_ID = 28@
    render_obj = 0@
end

Ped_ID = 155

            if or
                0EEA: locate_char_distance_to_coordinates $player_actor pos 372.4044 -70.5814 1001.5078 radius 30.0 // Burger
                0EEA: locate_char_distance_to_coordinates $player_actor pos 374.919 -123.8423 1001.4995 radius 30.0 // Pizza
            then
                if 0EEA: locate_char_distance_to_coordinates $player_actor pos 372.4044 -70.5814 1001.5078 radius 30.0 // Burger
                then gosub @Burger_coords
                end
                if 0EEA: locate_char_distance_to_coordinates $player_actor pos 374.919 -123.8423 1001.4995 radius 30.0 // Pizza
                then gosub @Pizza_coords
                end
                
                repeat
                wait 0
                04ED: load_animation  "PedEventsMod"
                until 04EE:   animation "PedEventsMod" loaded

                repeat
                wait 0
                04ED: load_animation  "COP_AMBIENT"
                until 04EE:   animation "COP_AMBIENT" loaded

                repeat
                wait 0
                04ED: load_animation  "SHOP"
                until 04EE:   animation "SHOP" loaded

                repeat
                wait 0
                04ED: load_animation  "GANGS"
                until 04EE:   animation "GANGS" loaded
            
            
                model.Load(Ped_ID)
                if
                    not model.Available(Ped_ID)
                then
                    repeat
                    wait 0
                    model.Load(Ped_ID)
                    until model.Available(Ped_ID)
                end
                038B: load_requested_models

                077E: get_active_interior_to 1@
                if 0EEA: locate_char_distance_to_coordinates $player_actor pos 372.4044 -70.5814 1001.5078 radius 30.0 // Burger
                then 009A: Chef_1 = create_actor_pedtype 4 model Ped_ID at 378.9782 -60.657 1001.5078
                else 009A: Chef_1 = create_actor_pedtype 4 model Ped_ID at 374.8675 -115.4769 1001.4922
                end
                0E24: fix_char Chef_1 ground 1 brightness 1 and_fade_in 0
                0860: link_actor Chef_1 to_interior 1@

                model.Destroy(Ped_ID)

                repeat
                wait 0
                if
                    056D:   actor Chef_1 defined
                then
                    080E: get_actor Chef_1 ped_event_to 1@
                    if or
                        051A:   actor Chef_1 damaged_by_actor $PLAYER_ACTOR
                        0118:   actor Chef_1 dead
                        1@ == 49
                        1@ == 9
                        1@ == 15
                        1@ == 31
                        1@ == 59
                    then
                        01C2: remove_references_to_actor Chef_1 // Like turning an actor into a random pedestrian
                        repeat
                        wait 0
                        0AAA: 1@ = get_script_struct_named 'JFUD'
                        until 1@ == 0
                        break
                    end
                    
                    if
                        0457:   player $PLAYER_CHAR aiming_at_actor Chef_1
                    then
                        0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 1@
                        0E89: get_weaponinfo_fire_type 1@ store_to 2@ //     
                        if or
                            2@ == 1 //  
                            2@ == 3 //   (  ..)
                        then
                            01C2: remove_references_to_actor Chef_1 // Like turning an actor into a random pedestrian
                            repeat
                            wait 0
                            0AAA: 1@ = get_script_struct_named 'JFUD'
                            until 1@ == 0
                            break
                        end
                    end
                    
                    if
                        not $ONMISSION == 0
                    then
                        if
                            056D:   actor $Actor_Ryder defined
                        then
                            if or
                                0611:   actor $Actor_Ryder performing_animation "ROB_Loop_Threat"
                                0611:   actor $Actor_Ryder performing_animation "ROB_Loop"
                                0611:   actor $Actor_Ryder performing_animation "ROB_2IDLE"
                                0611:   actor $Actor_Ryder performing_animation "PRTIAL_GNGTLKH"
                            then
                                if
                                    8611:   not actor Chef_1 performing_animation "SHP_Rob_HandsUp"
                                then
                                    0615: define_AS_pack_begin 1@
                                    0639: AS_actor -1 rotate_to_actor $Actor_Ryder
                                    0812: AS_actor -1 perform_animation "SHP_Rob_HandsUp" IFP "SHOP" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                                    0616: define_AS_pack_end 1@
                                    0618: assign_actor Chef_1 to_AS_pack 1@
                                    061B: remove_references_to_AS_pack 1@
                                    wait 300
                                    continue
                                end
                            end
                        end
                    end
                    
                    if
                        0611:   actor Chef_1 performing_animation "chef_2"
                    then
                        0613: 1@ = actor Chef_1 animation "chef_2" time
                        if
                            1@ > 0.95
                        then
                            0209: 1@ = random_int_in_ranges 1 4
                            if
                                1@ == 1
                            then
                                0804: AS_actor Chef_1 walk_to 14@ 15@ 16@ angle 17@ radius 0.0 animation "chef_1" IFP_file "PedEventsMod" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                wait 300
                                continue
                            end
                            if
                                1@ == 2
                            then
                                0804: AS_actor Chef_1 walk_to 22@ 23@ 24@ angle 25@ radius 0.0 animation "leanIDLE" IFP_file "GANGS" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                wait 300
                                continue
                            end
                            if
                                1@ == 3
                            then
                                wait 1000
                                continue
                            end
                        end
                    end
                    if
                        0611:   actor Chef_1 performing_animation "chef_1"
                    then
                        0613: 1@ = actor Chef_1 animation "chef_1" time
                        if
                            1@ > 0.95
                        then
                            0209: 1@ = random_int_in_ranges 1 3
                            if
                                1@ == 1
                            then
                                0209: 1@ = random_int_in_ranges 1 4
                                if 1@ == 1
                                then 0804: AS_actor Chef_1 walk_to 18@ 19@ 20@ angle 21@ radius 0.0 animation "Coplook_nod" IFP_file "COP_AMBIENT" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                end
                                if 1@ == 2
                                then 0804: AS_actor Chef_1 walk_to 18@ 19@ 20@ angle 21@ radius 0.0 animation "Coplook_shake" IFP_file "COP_AMBIENT" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                end
                                if 1@ == 3
                                then 0804: AS_actor Chef_1 walk_to 18@ 19@ 20@ angle 21@ radius 0.0 animation "Coplook_think" IFP_file "COP_AMBIENT" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                end
                                wait 300
                                continue
                            else
                                wait 1000
                                continue
                            end
                        end
                    end
                    if or
                        0611:   actor Chef_1 performing_animation "Coplook_nod"
                        0611:   actor Chef_1 performing_animation "Coplook_shake"
                        0611:   actor Chef_1 performing_animation "Coplook_think"
                    then
                        if 0611:   actor Chef_1 performing_animation "Coplook_nod"
                        then 0613: 1@ = actor Chef_1 animation "Coplook_nod" time
                        end
                        if 0611:   actor Chef_1 performing_animation "Coplook_shake"
                        then 0613: 1@ = actor Chef_1 animation "Coplook_shake" time
                        end
                        if 0611:   actor Chef_1 performing_animation "Coplook_think"
                        then 0613: 1@ = actor Chef_1 animation "Coplook_think" time
                        end
                        if
                            1@ > 0.95
                        then
                            0209: 1@ = random_int_in_ranges 1 4
                            if
                                1@ == 1
                            then
                                0804: AS_actor Chef_1 walk_to 10@ 11@ 12@ angle 13@ radius 0.0 animation "chef_2" IFP_file "PedEventsMod" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                wait 300
                                continue
                            end
                            if
                                1@ == 2
                            then
                                0804: AS_actor Chef_1 walk_to 14@ 15@ 16@ angle 17@ radius 0.0 animation "chef_1" IFP_file "PedEventsMod" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                wait 300
                                continue
                            end
                            if
                                1@ == 3
                            then
                                0804: AS_actor Chef_1 walk_to 22@ 23@ 24@ angle 25@ radius 0.0 animation "leanIDLE" IFP_file "GANGS" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                wait 300
                                continue
                            end
                        end
                    end
                    if
                        0611:   actor Chef_1 performing_animation "leanIDLE"
                    then
                        0613: 1@ = actor Chef_1 animation "leanIDLE" time
                        if and
                            timerb > 5000
                            1@ > 0.95
                        then
                            0209: 1@ = random_int_in_ranges 1 4
                            if
                                1@ == 1
                            then
                                0804: AS_actor Chef_1 walk_to 10@ 11@ 12@ angle 13@ radius 0.0 animation "chef_2" IFP_file "PedEventsMod" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                wait 300
                                continue
                            end
                            if
                                1@ == 2
                            then
                                0804: AS_actor Chef_1 walk_to 14@ 15@ 16@ angle 17@ radius 0.0 animation "chef_1" IFP_file "PedEventsMod" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                                wait 300
                                continue
                            end
                            if
                                1@ == 3
                            then
                                wait 1000
                                continue
                            end
                        end
                    else
                        timerb = 0
                    end
                    
                    0EFF: get_char_simplest_active_task Chef_1 id_to 1@ pointer_to 2@
                    if and
                        1@ == 203
                        timera > 2000
                    then
                        timera = 0
                        0804: AS_actor Chef_1 walk_to 10@ 11@ 12@ angle 13@ radius 0.0 animation "chef_2" IFP_file "PedEventsMod" rate 2.0 LA 1 LX 0 LY 0 LF 0 LT -1
                        wait 300
                        continue
                    else
                        if or
                            1@ == 401
                            1@ == 900
                        then
                            timera = 0
                        end
                    end
                end
                0AAA: 1@ = get_script_struct_named 'JFUD'
                until 1@ == 0

                if 056D:   actor Chef_1 defined
                then 009B: destroy_actor Chef_1
                end
                04EF: release_animation "PedEventsMod"
                04EF: release_animation "COP_AMBIENT"
                04EF: release_animation "GANGS"
                04EF: release_animation "SHOP"
            end

            if
                0EEA: locate_char_distance_to_coordinates $player_actor pos 370.1673 -3.3784 1001.8516 radius 30.0 // Cluckin bell
            then
                0AF0: Ped_ID = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "Chef CLUCKIN PED ID"
            
                model.Load(Ped_ID)
                038B: load_requested_models

                077E: get_active_interior_to 1@
                009A: Chef_1 = create_actor_pedtype 4 model Ped_ID at 370.1673 -3.3784 1001.8516
                0E24: fix_char Chef_1 ground 1 brightness 1 and_fade_in 0
                0860: link_actor Chef_1 to_interior 1@
                0173: set_actor $PLAYER_ACTOR Z_angle_to 0.0

                model.Destroy(Ped_ID)

                repeat
                wait 0
                04ED: load_animation  "PedEventsMod"
                until 04EE:   animation "PedEventsMod" loaded
                
                0812: AS_actor Chef_1 perform_animation "chef_2" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                
                repeat
                wait 0
                if
                    056D:   actor Chef_1 defined
                then
                
                    080E: get_actor Chef_1 ped_event_to 1@
                    if or
                        051A:   actor Chef_1 damaged_by_actor $PLAYER_ACTOR
                        0118:   actor Chef_1 dead
                        1@ == 49
                        1@ == 9
                        1@ == 15
                        1@ == 31
                        1@ == 59
                    then
                        01C2: remove_references_to_actor Chef_1 // Like turning an actor into a random pedestrian
                        repeat
                        wait 0
                        0AAA: 1@ = get_script_struct_named 'JFUD'
                        until 1@ == 0
                        break
                    end

                    if
                        0457:   player $PLAYER_CHAR aiming_at_actor Chef_1
                    then
                        0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 1@
                        0E89: get_weaponinfo_fire_type 1@ store_to 2@ //     
                        if or
                            2@ == 1 //  
                            2@ == 3 //   (  ..)
                        then
                            01C2: remove_references_to_actor Chef_1 // Like turning an actor into a random pedestrian
                            repeat
                            wait 0
                            0AAA: 1@ = get_script_struct_named 'JFUD'
                            until 1@ == 0
                            break
                        end
                    end
                    
                    if
                        0611:   actor Chef_1 performing_animation "chef_2"
                    then
                        timera = 0
                    end
                    
                    0EFF: get_char_simplest_active_task Chef_1 id_to 1@ pointer_to 2@
                    if and
                        1@ == 203
                        timera > 2000
                    then
                        0812: AS_actor Chef_1 perform_animation "chef_2" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1  // versionB
                        wait 300
                        continue
                    end
                end
                0AAA: 1@ = get_script_struct_named 'JFUD'
                until 1@ == 0
                
                if 056D:   actor Chef_1 defined
                then 009B: destroy_actor Chef_1
                end
                04EF: release_animation "PedEventsMod"
            end
            
0A93: terminate_this_custom_script

:Burger_coords
0AF0: Ped_ID = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "Chef BURGER PED ID"

// Chef_2
10@ = 376.0 
11@ = -60.6488
12@ = 1001.5078
13@ = 90.0

// Chef_1
14@ = 378.3445
15@ = -57.1
16@ = 1001.5078
17@ = 0.0

// Look
18@ = 377.6866
19@ = -62.4314
20@ = 1001.5078
21@ = 165.0

// Lean
22@ = 380.5243
23@ = -62.5901
24@ = 1001.5078
25@ = 0.0
return

:Pizza_coords
0AF0: Ped_ID = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "Chef PIZZA PED ID"

// Chef_2
10@ = 374.8849
11@ = -113.2217
12@ = 1001.4922
13@ = 360.0

// Chef_1
14@ = 378.6354 
15@ = -113.5043
16@ = 1001.4922
17@ = 0.0

// Look
18@ = 375.4373
19@ = -115.9776
20@ = 1001.4922
21@ = 180.0

// Lean
22@ = 379.2398
23@ = -114.6193
24@ = 1001.5078
25@ = 90.0
return
